package cn.tj212.xiaoyin.controller;

import cn.tj212.xiaoyin.dto.CodeMsg;
import cn.tj212.xiaoyin.dto.ResponseObj;
import cn.tj212.xiaoyin.util.ValidateUtil;
import cn.tj212.xiaoyin.vo.LoginVo;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import org.slf4j.Logger;

@RequestMapping("/login")
@Controller
public class LoginController {

    private static Logger logger= LoggerFactory.getLogger(LoginController.class);

    @RequestMapping("/login")
    public String login(){
        return "login";
    }

    @RequestMapping("/doLogin")
    @ResponseBody
    public ResponseObj<Boolean> doLogin(LoginVo loginVo){
        logger.info(loginVo.toString());
        //参数校验
        String passInput=loginVo.getPassword();
        String mobile=loginVo.getMobile();
        if (StringUtils.isEmpty(passInput)){
            return ResponseObj.error(CodeMsg.PASSWORD_EMPTY);
        }
        if (StringUtils.isEmpty(mobile)){
            return ResponseObj.error(CodeMsg.MOBILE_EMPTY);
        }
        if (ValidateUtil.isMobile(mobile)){
            return ResponseObj.error(CodeMsg.MOBILE_ERROR);
        }


        return null;
    }
}
